package com.sx.gongzhong.pest;

import com.sx.gongzhong.model.CommentBean;
import com.sx.gongzhong.model.DefendRoadBean;
import com.sx.gongzhong.model.HeadParamBean;
import com.sx.gongzhong.model.ReplyUserBean;
import com.sx.gongzhong.net.ApiManager;
import com.sx.gongzhong.net.BaseCallBack;
import com.sx.gongzhong.model.BasePageListBean;
import com.sx.gongzhong.view.IDefendRoadDetailView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2018/1/9.
 * 全民护路详情
 */

public class DefendRoadDetailPest {

    private IDefendRoadDetailView detailView;

    public DefendRoadDetailPest(IDefendRoadDetailView detailView) {
        this.detailView = detailView;
    }

    /**
     * 全民护路详情
     * @param protectionId 护路id
     */
    public void loadDefendRoadDetail(String protectionId){
        Map<String,Object> map= new HashMap<>();
        map.put("protectionId", protectionId);

        new ApiManager().loadDefendRoadDetail(map, new BaseCallBack<ReplyUserBean.BaseResult<DefendRoadBean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<DefendRoadBean> response) {
                detailView.loadDefendRoadDetail(response.getData());
            }
            @Override
            public void onFailures(String message) {
                detailView.showError("获取详情失败");
            }
        });

    }

    /**
     * 删除全民护路
     * @param dataID 数据id
     */
    public void deleteDefendRoad(String dataID){
        Map<String,Object> map= HeadParamBean.getHead();
        map.put("ids", dataID);
        new ApiManager().deleteDefendRoad(map, new BaseCallBack<ReplyUserBean.BaseResult<Boolean>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<Boolean> response) {
                detailView.deleteExposure("删除成功");
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });
    }

    /**
     *  回复列表
     * @param dataId 数据id
     * @param page 页数
     * @param rows 条数
     */
    public void loadDefendRoadReplyList(String dataId, int page, final int rows){
        Map<String,Object> map= new HashMap<>();
        map.put("dataId", dataId);
        map.put("page", page);
        map.put("rows", rows);
        new ApiManager().loadDefendRoadReplyList(map, new BaseCallBack<ReplyUserBean.BaseResult<BasePageListBean<CommentBean>>>() {
            @Override
            public void onSuccess(ReplyUserBean.BaseResult<BasePageListBean<CommentBean>> response) {
                detailView.loadExposureReplyList(response.getData().rows,response.getData().records);
            }
            @Override
            public void onFailures(String message) {
                detailView.showError(message);
            }
        });
    }


}
